Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
JS cannot read proprieties of null "innerHTML" on onload call

I have a function that will display content of item prices which can have their order changed from ascending to descending from the click of a button as well as the buttons innerHTML being changed to display text showing what order they are being displayed in. The onload function is called at the top of my HTML code. There is a check inside my function to see in innerHTML of the button (so it changes to the opposite value each time it is clicked) but when i call the function on onload it appears in console as

'Cannot read properties of null (reading 'innerHTML') at ....... at HTMLScriptElement.onload'

JS function:

function myFunc() {
    var elem = document.getElementById("selectionButton")
    if (elem.innerHTML=="descending") { elem.innerHTML = "ascending "}
    else { elem.innerHTML = "descending"}

Onload:

<script src="script.js" onload="myFunc()" ></script>

Buttons:

<button onclick="myFunc()" id="selectionButton" >Ascending</button>
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!